﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.FxCop.Sdk;

namespace BovespaNamingRules
{
    public sealed class Rule_BovespaArrayCollectionNamesPlural : BaseAddIn.Rules.BaseRuleFXCop
    {
        #region Constructor

        public Rule_BovespaArrayCollectionNamesPlural() :
            base("BovespaArrayCollectionNamesPlural", "BovespaNamingRules.BovespaNamingRules", typeof(Rule_BovespaArrayCollectionNamesPlural).Assembly)
        {
        }

        #endregion

        #region Public Override Methods

        public sealed override ProblemCollection Check(Member member)
        {
            switch (member.NodeType)
            {
                case NodeType.Method:
                    ExecCheckMethod(member);
                    break;
                case NodeType.Property:
                    ExecCheckProperty(member);
                    break;
                case NodeType.Field:
                    ExecCheckField(member);
                    break;
            }
            
            return this.Problems;
        }


        #endregion

        #region Private Methods

        private bool CkeckName(string type, string name)
        {
			//if (name.Contains("$"))
			//    return true;
            
			//if ((type.Contains("[") || type.ToUpper().Contains("COLLECTION")))
			//{
			//    if (name.ToUpper().EndsWith("S"))
			//        return true;
			//    else
			//        return false;
			//}
            
            return true;
        }

        private void ExecCheckMethod(Member member)
        {
			//Method method = member as Method;

			//if (method != null)
			//{
			//    if (method.DeclaringMember == null ||
			//        (method.DeclaringMember != null &&
			//        method.DeclaringMember.NodeType != NodeType.Property &&
			//        !method.Name.Name.ToUpper().StartsWith("get_") &&
			//        !method.Name.Name.ToUpper().StartsWith("set_")))
			//    {
			//        foreach (Parameter param in method.Parameters)
			//        {
			//            if (!this.CkeckName(param.Type.FullName, param.Name.Name))
			//                AddError(member, "BovespaArrayCollectionNamesPluralResolution2", param.Name.Name, member.DeclaringType.Name.Name, member.DeclaringType.Namespace.Name);
			//        }

			//        this.VerifyLocal(method.Locals);
			//    }
			//}
        }

        private void ExecCheckProperty(Member member)
        {
			//PropertyNode property = member as PropertyNode;

			//if (property != null)
			//{
			//    if (!this.CkeckName(property.Type.FullName, property.Name.Name))
			//        AddError(member, "BovespaArrayCollectionNamesPluralResolution2", property.Name.Name, member.DeclaringType.Name.Name, member.DeclaringType.Namespace.Name);
			//}
        }

        private void ExecCheckField(Member member)
        {
			//Field field = member as Field;

			//if (field != null)
			//{
			//    if (!this.CkeckName(field.Type.FullName, field.Name.Name))
			//        AddError(member, "BovespaArrayCollectionNamesPluralResolution2", field.Name.Name, member.DeclaringType.Name.Name, member.DeclaringType.Namespace.Name);
			//}
        }

        private void VerifyLocal(LocalCollection locals)
        {
			//if (locals != null)
			//{
			//    foreach (Local local in locals)
			//    {
			//        if (!this.CkeckName(local.Type.FullName, local.Name.Name))
			//            AddError(local, "BovespaArrayCollectionNamesPluralResolution1", local.Name.Name);
			//    }
			//}
        }

        #endregion
    }
}
